package com.sr.demo.security.nuouser.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sr.demo.security.nuouser.dao.NuoUserDAO;
import com.sr.demo.security.nuouser.dto.NuoUserDTO;
import com.sr.demo.security.nuouser.entity.NuoUserEntity;
import com.sr.demo.security.nuouser.service.NuoUserService;
import com.sr.demo.security.password.NuoPasswordEncoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 用户表(NuoUser)表服务实现类
 *
 * @author liushuai
 * @since 2021-02-13 22:10:05
 */
@Service("nuoUserService")
public class NuoUserServiceImpl extends ServiceImpl<NuoUserDAO, NuoUserEntity> implements NuoUserService {

    @Autowired
    private NuoUserDAO nuoUserDao;
    @Autowired
    private NuoPasswordEncoder nuoPasswordEncoder;


    @Override
    public void saveUser(NuoUserDTO nuoUserDTO) {
        if(StrUtil.isNotBlank(nuoUserDTO.getPassword())){
            nuoUserDTO.setPassword(nuoPasswordEncoder.encode(nuoUserDTO.getPassword()));
        }
        NuoUserEntity userEntity = Convert.convert(NuoUserEntity.class, nuoUserDTO);
        userEntity.setDeptId("1");
        this.saveOrUpdate(userEntity);
    }
}